package com.test.testapp.app;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.PopupWindow;


public class MainActivity extends Activity {

    private Dialog dialog;
    private PopupWindow aboutUsPopUp;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new ImageAdapter(this));
        //click listener voor de grid view(dient te worden uitgebreid wanneer nieuwe items worden toegevoegd
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

                Intent myIntent = null;
                if (position == 0) {
                    myIntent = new Intent(getApplicationContext(), RDW.class);
                }
                if (position == 1) {
                    myIntent = new Intent(getApplicationContext(), BuienRadar.class);
                }
                if (position == 2) {
                    myIntent = new Intent(getApplicationContext(), KNMI.class);
                }
                if (position == 3) {
                    myIntent = new Intent(getApplicationContext(), OpenWeather.class);
                }
                startActivity(myIntent);
            }



        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_about) {
            popupAboutUs();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    // creeren en weergeven van de popup aan de hand van de popup xml in de layout map
    private void popupAboutUs()
    {
        View popUpView = getLayoutInflater().inflate(R.layout.popup, null); // inflating popup layout
        aboutUsPopUp = new PopupWindow(popUpView, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); //Creation of popup
        aboutUsPopUp.setAnimationStyle(android.R.style.Animation_Dialog);
        aboutUsPopUp.showAtLocation(popUpView, Gravity.CENTER_VERTICAL, 0, 0);    // Displaying popup

        Button btnCancel = (Button)popUpView.findViewById(R.id.btnCancel);
        btnCancel.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                aboutUsPopUp.dismiss(); //dismissing the popup
            }
        });
    }
}


